<template>
	<view>
		<u-row customStyle="margin-bottom: 80px">
			<u-col span="12">
				<view>
					<u-navbar
					    title="求职意向"
						titleStyle="font-weight:bold"
					    :safeAreaInsetTop="true"
						:fixed='true'
						bgColor="#FFBE59"
						@leftClick="leftClick"
						@rightClick="delIntention"
					>
					    <view
					        class="u-nav-slot"
					        slot="left"
							
					    >
					        <u-icon
					            name="arrow-left"
					            size="20"
								color="black"
					        ></u-icon>
					    </view>
						<view
						    class="u-nav-slot"
						    slot="right"
						>
						    <u-icon
								v-if="this.jobId!=''"
						        name="trash"
						        size="22"
								color="black"
						    ></u-icon>
						</view>
					</u-navbar>
				</view>
			</u-col>
		</u-row>
		<u-modal :show="showConfirm" @confirm="confirmFunction()" @cancel="cancelFunction()" width="250px" :content='contentConfirm' :showCancelButton='true'></u-modal>
		<u-row customStyle="margin-bottom: 10px">
			<u-col span="11" style="margin: 0 auto">
				<view class="resume bg-purple-light">
					<u-col span="12">
						<view class="expected-position bg-purple-light">
							<p>期望职位</p>
						<u--input
						    placeholder="例: Java"
						    border="bottom"
							v-model="positionValue"
						    clearable
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="expected-industry bg-purple-light">
							<p>期望行业</p>
						<u--input
						    placeholder="例: 计算机软件"
						    border="bottom"
						    clearable
							v-model="industryValue"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="work-city bg-purple-light">
							<p>工作城市</p>
						<u--input
						    placeholder="例: 北京"
						    border="bottom"
						    clearable
							v-model="cityValue"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="salary-expectation bg-purple-light">
							<p>期望薪资</p>
						<u--input
						    placeholder="例: 8千/0.8万"
						    border="bottom"
						    clearable
							type="text"
							v-model="salaryValue"
						  ></u--input>
						</view>
					</u-col>
					<u-col span="12">
						<view class="keep-button bg-purple-light">
							<u-button type="primary" @click="subForm()" text="保存"></u-button>
						</view>
					</u-col>
				</view>
			</u-col>
		</u-row>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				positionValue:'',
				industryValue:'',
				cityValue:'',
				salaryValue:'',
				jobIntention:{},
				jobId:'',//求职意向id
				resumeId:'',//简历id
				flag:true,
				subUrl:"",
				showConfirm:false,
				contentConfirm:'',
			}
		},
		created(){
			if(this.jobId!=""){
				this.$axios.get('/resume/employmentResume/queryPositonIntentionListById?id='+this.jobId).then((res)=>{
					if(res.data.result){
						this.jobIntention = res.data.result;
						this.positionValue = this.jobIntention.positionTypeId;
						this.industryValue = this.jobIntention.industryTypeId;
						this.cityValue = this.jobIntention.addressId;
						this.salaryValue = this.jobIntention.salaryExpectation;
					}
				});
			}
		},
		methods: {
			//左侧点击返回上一页面
			leftClick(){
				uni.reLaunch({
					url: '/pages/service/practicaltrainingservice/resume/resume',
				});
			},
			//删除的对话窗
			delIntention(){
				this.showConfirm = true;
				this.contentConfirm = "确认要删除吗？";
			},
			confirmFunction(){//确认按钮
				this.$axios.get('/resume/employmentResume/delPositonIntentionListById?id='+this.jobIntention.id).then((res)=>{
					if(res.data.success){//true
						uni.redirectTo({
							url: '/pages/service/practicaltrainingservice/resume/resume',
						});
					}else{
						uni.showToast({
							icon: 'error',
							position: 'bottom',
							title: '删除失败'
						});
					}
				});
			},
			cancelFunction(){//确认按钮
				this.showConfirm = false;
			},
			//保存
			subForm(){
				if(this.positionValue==""||this.positionValue==undefined){
					this.flag = false;
				}
				if(this.industryValue==""||this.industryValue==undefined){
					this.flag = false;
				}
				if(this.cityValue==""||this.cityValue==undefined){
					this.flag = false;
				}
				if(this.salaryValue==""||this.salaryValue==undefined){
					this.flag = false;
				}
				if(this.flag!=false){
					//将各value值赋值给对象
					this.jobIntention.resumeId = this.resumeId;
					this.jobIntention.positionTypeId = this.positionValue;
					this.jobIntention.industryTypeId = this.industryValue;
					this.jobIntention.addressId = this.cityValue;
					this.jobIntention.salaryExpectation = this.salaryValue;
					//判断是新增还是修改 
					if(this.jobId!=""){//修改
						this.subUrl = "/resume/employmentResume/upPositonIntention";
					}else{//新增
						this.subUrl = "/resume/employmentResume/addPositonIntention";
					}
					//保存求职意向
					this.$axios.post(this.subUrl,this.jobIntention).then((res)=>{
						if(res.data.success){//true
							uni.redirectTo({
								url: '/pages/service/practicaltrainingservice/resume/resume',
							});
						}else{
							uni.showToast({
								icon: 'error',
								position: 'bottom',
								title: '操作失败'
							});
						}
					});
				}else{
					uni.showToast({
						icon: 'error',
						position: 'bottom',
						title: '信息填写不完整'
					});
				}
			},
		},
		onLoad: function (option) { //option为object类型，会序列化上个页面传递的参数
			this.jobId = option.jobId;
			this.resumeId = option.id;
		}
	}
</script>

<style>
	p{font-size: 14px;margin-left: 8px;color: #3C3C3C;}
	.expected-position,.expected-industry,.work-city,.salary-expectation,.keep-button{margin-top: 20px;}
	
</style>